import Cookies from 'js-cookie'

const state = {
  token: Cookies.get('token'),
  thirdToken: Cookies.get('thirdToken'),
  contextToken: Cookies.get('contextToken'),
  lxbToken:Cookies.get('lxbToken'),
  refreshToken:Cookies.get('refreshToken')
}

// getters
const getters = {
  getToken: state => state.token,
  getThirdToken: state => state.thirdToken,
  getcontextToken: state => state.contextToken,
  getLxbToken: state => state.lxbToken,
  getRefreshToken: state => state.refreshToken
}

// actions
const actions = {
  setToken ({ commit }, token) {
    Cookies.set('token', token)
    commit('SET_TOKEN', { token })
  },
  removeToken ({ commit }) {
    Cookies.remove('token')
    commit('REMOVE_TOKEN')
  },
  setThirdToken ({ commit }, token) {
    Cookies.set('thirdToken', token)
    commit('SET_THIRD_TOKEN', { token })
  },
  removeThirdToken ({ commit }) {
    Cookies.remove('thirdToken')
    commit('REMOVE_THIRD_TOKEN')
  },
  setContextToken ({ commit }, token) {
    Cookies.set('contextToken', token)
    commit('SET_CONTEXT_TOKEN', { token })
  },
  removeContextToken ({ commit }) {
    Cookies.remove('contextToken')
    commit('REMOVE_CONTEXT_TOKEN')
  },
  setLxbToken ({ commit }, token) {
    Cookies.set('lxbToken', token)
    commit('SET_LXB_TOKEN', { token })
  },
  removeLxbToken ({ commit }) {
    Cookies.remove('lxbToken')
    commit('REMOVE_LXB_TOKEN')
  },
  setRefreshToken ({ commit }, token) {
    Cookies.set('refreshToken', token)
    commit('SET_REFRESH_TOKEN', { token })
  },
  removeRefreshToken ({ commit }, token) {
    Cookies.remove('refreshToken', token)
    commit('REMOVE_REFRESH_TOKEN')
  }
}

// mutations
const mutations = {
  SET_TOKEN (state, { token }) {
    state.token = token
  },
  REMOVE_TOKEN (state) {
    state.token = null
  },
  SET_THIRD_TOKEN (state, { token }) {
    state.thirdToken = token
  },
  REMOVE_THIRD_TOKEN (state) {
    state.thirdToken = null
  },
  SET_CONTEXT_TOKEN (state, { token }) {
    state.contextToken = token
  },
  REMOVE_CONTEXT_TOKEN(state) {
    state.contextToken = null
  },
  SET_LXB_TOKEN (state, { token }) {
    state.lxbToken = token
  },
  REMOVE_LXB_TOKEN (state) {
    state.lxbToken = null
  },
  SET_REFRESH_TOKEN (state, { token }) {
    state.refreshToken = token
  },
  REMOVE_REFRESH_TOKEN (state) {
    state.refreshToken = null
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
